package com.orchidea.uml.view
{
import com.orchidea.uml.model.UmlEntityType;

import com.orchidea.uml.model.document.Entity;

import flash.utils.Dictionary;

import mx.core.Container;

/**
	 * A factory for element views that can create the appropriate view instance for a particular element type.
	 */
    public class DocumentElementViewFactory
    {
        private static var _factoryMap : Dictionary;


		private function get factoryMap( ) : Dictionary
        {
			if ( _factoryMap == null ) {
				_factoryMap = new Dictionary();
				_factoryMap[UmlEntityType.CLASS]  = DocumentElement;
			}

			return _factoryMap;
		}



        /**
		 * Creates a view that can display the specified UML element.
		 *
		 * Throws an exception if the element is null or if the element type is not supported.
		 */
		public function createView( element : Entity ) : Container
        {
			if ( element == null ) {
				throw new ArgumentError("Cannot create element view, element was null");
			}

			if ( factoryMap[element.type] == null ) {
				throw new ArgumentError("Cannot create new element view, unknown type: \"" + element.type + "\"");
			}

			var viewClass : Class = factoryMap[element.type];

			var view : Container = new viewClass();

			view.data = element;

			return view;
		}
    }
}